<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/10/30
 * Time: 11:51 AM
 */

namespace app\activity\logic;


use extend\Functions;
use extend\STATUS_CODE;

class Sms
{
    /**
     * @purpose 找回密码时获取验证码
     * @param string $mobile
     * @return array
     */
    public static function authCodeForFindPassword (string $mobile): array
    {
        $model      = new \app\model\Member();
        if ($model->total(['mobile' => $mobile]) < 1) {
            return Functions::result(
                STATUS_CODE::PARAMETER_ERROR,
                '手机号码不存在...!'
            );
        }
        return \extend\SMS::smsCode($mobile);
    }
    /**
     * @purpose 获取更改手机号码时的验证码
     * @param $mobile
     * @return array
     */
    public static function authCodeForChange ($mobile): array
    {
        $model      = new \app\model\Member();
        if ($model->total(['mobile' => $mobile]) > 0) {
            return Functions::result(
                STATUS_CODE::PARAMETER_ERROR,
                '该手机号码已绑定其他账户'
            );
        }
        return \extend\SMS::smsCode($mobile);
    }

    /**
     * @purpose 绑定时获取手机验证码
     * @param string $mobile
     * @return array
     */
    public static function bindSmsCode (string $mobile): array
    {
        $model      = new \app\model\Member();
        if ($model->total(['mobile' => $mobile]) < 1) {
            return Functions::result(
                STATUS_CODE::PARAMETER_ERROR,
                '该手机号码并没有注册过欢乐账号...!'
            );
        }
        return \extend\SMS::smsCode($mobile);
    }
}